<template>
  <el-tree-select
    v-model="deptName"
    :props="{ label: 'label', children: 'children' }"
    :data="deptOptions"
    :check-strictly="true"
    :render-after-expand="false"
    @change="deptChange"
  />
</template>

<script setup name="MatTypeSelect">
import {
  queryMatTypeInfoList,
  getMatTypeData,
  deleteMatTypeInfo,
  addMatTypeInfo,
  updateMatTypeInfo,
  syncErpMaterial,
} from "@/api/base/material/MatTypeApi";

function load(row, treeNode, resolve) {
  let level = row.level;
  if (!row.level) {
    level = 1;
  }
  queryMatTypeInfoList({ level: level + 1 })
    .then((response) => {
      const subData = [];
      response.rows.forEach((el) => {
        if (el.code.includes(row.code)) {
          el.children = [];
          el.parentName = row.name;
          el.parentCode = row.code;
          el.hasChildren = true;
          subData.push(el);
        }
      });
      resolve(subData);
    })
    .catch(() => {
      resolve([]);
    });
}

/** 查询物料分类列表 */
function getList() {
  loading.value = true;
  tableData.value = [];
  queryMatTypeInfoList({ pageNum: 1, pageSize: 10000 }).then((response) => {
    response.rows.forEach((el) => {
      el.children = [];
      el.hasChildren = true;
    });
    tableData.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
</script>

<style lang="scss" scoped></style>
